package com.mk.task;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.mk.entity.Pet;
import com.mk.mapper.PetMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@RequiredArgsConstructor
public class PetPointsTask {

    private final PetMapper petMapper;

    @Scheduled(cron = "${task.recoverPointScheduled.cron}")
    public void recoverPoint() {
        LocalDateTime now = LocalDateTime.now();

        petMapper.update(new LambdaUpdateWrapper<Pet>()
                .set(Pet::getScore, 12)
                .set(Pet::getScoreTime, now)
                .set(Pet::getUpdateTime, now)
                .le(Pet::getScoreTime, now.minusYears(1)));

    }
}
